package com.ly.lypopupwindowdemo.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;

import com.ly.lypopupwindowdemo.R;

public class MyWebViewActivity extends AppCompatActivity {

    private Button back;
    private TextView title;
    private WebView webView;

    /**
     * load一个网页
     *
     * @param context
     * @param title
     * @param url
     */
    public static void startWebView(Context context, String title, String url) {
        Intent intent = new Intent(context, MyWebViewActivity.class);
        intent.putExtra("title", title);
        intent.putExtra("linkItem", url);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_web_view);

        back = (Button) findViewById(R.id.back);
        title = (TextView) findViewById(R.id.title);
        webView = (WebView) findViewById(R.id.webview);

        String strItem = getIntent().getStringExtra("linkItem");
        String title_str = getIntent().getStringExtra("title");

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        WebSettings ws = webView.getSettings();
        ws.setJavaScriptEnabled(true);

        webView.loadUrl(strItem);
        title.setText(title_str);

        webView.setWebViewClient(new WebViewClient(){
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                webView.loadUrl(url);

                return true;
            }
        });

    }
}
